home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINPROGS
/
WUNZ20SR.ZIP
/
STATUS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-07
|
28KB
|
745 lines
/* Status.c -- the status module of WizUnZip
* Robert Heath. 1991.
*/
#include <sys\types.h>
#include <sys\stat.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include <io.h>
#include <stdio.h>
#include <stdarg.h>
#include "wizunzip.h"
#include "unzip.h"
#define STATUS_INCREMENT 512 /* incremental status data size */
#define MAX_H_CHARS 160 /* max horizontal chars. */
#define MAX_INDEX_ENTRIES 16 /* Message Window index max entries */
#define cchBufferMax 0xffffL /* max Message Buffer size. Must fit
* within one memory segment! */
#define cchTextOutMax 0x7fffL /* max no. bytes TextOut() accepts */
#define STDIO_BUF_SIZE (FILNAMSIZ+LONG_FORM_FNAME_INX) /* buffer size during printf or fprintf */
static short yClient; /* height of client area */
static short nVscrollPos = 0; /* scroll position of mesg. window */
static short nNumLines = 0; /* number of lines in buffer */
static short nVscrollMax; /* max scroll position of mesg. window */
static DWORD dwStatusSize = 0L; /* status data size */
static DWORD dwBufferSize = 0L; /* Status buffer size. Never
exceeds cchBufferMax */
static HANDLE hStatusBuffer; /* global mesg. handle */
static DWORD rgidwMsgWin[MAX_INDEX_ENTRIES]; /* max index entries */
static short cMsgWinEntries; /* no. active index entries, with
MAX_INDEX_ENTRIES as its max.
When set to 0, it's time to
re-index.*/
static short nLinesPerEntry; /* lines per index entry */
/* displayed when buffer shouldn't grow or can't grow */
static char __based(__segname("STRINGS_TEXT")) szClearBufferMsg[] =
"Clearing Status window to make room for more information.";
/* displayed when buffer shouldn't grow or can't grow */
static char __based(__segname("STRINGS_TEXT")) szCantClipboard[] =
"Cannot get enough memory to copy Status window to clipboard.";
struct KeyEntry
{
WORD wVirtKey;
BOOL bCntl;
WORD wMessage;
WORD wRequest;
} __based(__segname("STRINGS_TEXT")) KeyTable[] =
{
/* vertical scroll control */
{VK_HOME, TRUE, WM_VSCROLL, SB_TOP },
{VK_END, TRUE, WM_VSCROLL, SB_BOTTOM },
{VK_PRIOR, FALSE, WM_VSCROLL, SB_PAGEUP },
{VK_NEXT, FALSE, WM_VSCROLL, SB_PAGEDOWN },
{VK_UP, FALSE, WM_VSCROLL, SB_LINEUP },
{VK_DOWN, FALSE, WM_VSCROLL, SB_LINEDOWN },
/* horizontal scroll control */
{VK_HOME, FALSE, WM_HSCROLL, SB_TOP },
{VK_END, FALSE, WM_HSCROLL, SB_BOTTOM },
{VK_PRIOR, TRUE, WM_HSCROLL, SB_PAGEUP },
{VK_NEXT, TRUE, WM_HSCROLL, SB_PAGEDOWN },
{VK_LEFT, FALSE, WM_HSCROLL, SB_LINEUP },
{VK_RIGHT, FALSE, WM_HSCROLL, SB_LINEDOWN },
} ;
#define NUMKEYS (sizeof(KeyTable)/sizeof(struct KeyEntry))
/* Forward Refs
*/
static void FreeStatusLog(void);
/* Globals */
BOOL bRealTimeMsgUpdate = TRUE; /* update messages window in real-time.
* Reset by callers when update can be
* be deferred.
*/
BOOL gfCancelDisplay = FALSE; /* cancel display if got in over our heads */
/* Clears status buffer. Frees buffer.
*/
static void FreeStatusLog(void)
{
if (hStatusBuffer)
{
GlobalFree(hStatusBuffer);
hStatusBuffer = (HANDLE)0;
}
dwStatusSize = 0L; /* status data size */
dwBufferSize = 0L; /* status buffer size */
nNumLines = 0; /* number of lines in buffer */
nVscrollMax = 1;
SetScrollRange(hWndStatus, SB_VERT, 0, 1, FALSE);
nVscrollPos = 0;
SetScrollPos(hWndStatus, SB_VERT, nVscrollPos, TRUE);
}
/* Update Message Window Position is called after adding
* a number of lines to the message window without updating it.
* The function invalidates then updates the window.
*/
void UpdateMsgWndPos(void)
{
nVscrollPos = max(0,(nNumLines-cLinesMessageWin+1)); /* set position to next to last line */
SetScrollPos(hWndStatus, SB_VERT, nVscrollPos, TRUE);
InvalidateRect(hWndStatus, NULL, TRUE);
UpdateWindow(hWndStatus);
}
/* Set Status Top Window Position is called after adding
* a number of lines to the message window without updating it.
* Unlike UpdateMsgWndPos() above, this function sets the
* status window position to the top.
* The function invalidates then updates the window.
*/
void SetStatusTopWndPos(void)
{
nVscrollPos = 0; /* set position to next to top line */
SetScrollPos(hWndStatus, SB_VERT, nVscrollPos, TRUE);
InvalidateRect(hWndStatus, NULL, TRUE);
UpdateWindow(hWndStatus);
}
/* Add message line (or part of a line) to the global status buffer
* that is the contents of the Message Window.
* Assumes that global data is unlocked when called.
*/
void WriteStringToMsgWin(PSTR psz, BOOL bUpdate)
{
WriteBufferToMsgWin(psz, strlen(psz), bUpdate);
}
/* Add message buffer (maybe part of a line) to the global status buffer
* that is the contents of the Message Window.
* Assumes that global data is unlocked when called.
*/
void WriteBufferToMsgWin(LPSTR pszBuffer, int nBufferLen, BOOL bUpdate)
{
LPSTR lpszT; /* pointer into buffer */
HANDLE hStatusBufferTmp;
LPSTR lpGlobalBuffer; /* pointer into global buffer */
DWORD dwNewSize = dwStatusSize + (DWORD)nBufferLen;
int nIncrLines = 0; /* incremental lines in buffer */
int nIncompleteExistingLine = 0; /* add -1 if incomplete existing last line */
int nIncompleteAddedLine = 0; /* add +1 if incomplete added last line */
DWORD dwRequestedSize; /* Size needed to hold all data. Can't
practically exceeded cchBufferMax.*/
if (gfCancelDisplay) /* if canceling display (in the middle of a lengthy operation) */
return; /* just discard data */
if (!nBufferLen) /* if no data */
return; /* just beat it */
/* count LF's in buffer to later add to total */
for (lpszT = pszBuffer; lpszT != NULL && (lpszT - pszBuffer) < nBufferLen; )
{
/* use memchr() for speed (?) considerations */
if (lpszT = _fmemchr(lpszT, '\n', (size_t)(nBufferLen - (lpszT - pszBuffer))))
{
nIncrLines++; /* tally line found */
lpszT++; /* point beyond LF for next pass */
}
}
if (dwNewSize > dwBufferSize) /* if won't fit or 1st time */
{
/* Round up if necessary to nearest whole increment */
dwRequestedSize = ((dwNewSize + STATUS_INCREMENT - 1) /
STATUS_INCREMENT) * STATUS_INCREMENT;
if (hStatusBuffer) /* if buffer exists, realloc */
{
if (dwRequestedSize <= cchBufferMax &&
(hStatusBufferTmp = GlobalReAlloc(hStatusBuffer,
dwRequestedSize, GMEM_MOVEABLE)))
{
/* successful re-allocation */
hStatusBuffer = hStatusBufferTmp;
dwBufferSize = dwRequestedSize;
}
else /* re-allocation failed, make last-ditch attempt! */
{
FreeStatusLog(); /* free own buffers */
if (MessageBox (hWndMain, szClearBufferMsg,
"Note", MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL)
gfCancelDisplay = TRUE;
else /* no cancel */
WriteBufferToMsgWin(pszBuffer, nBufferLen, bUpdate);
return;
}
}
else /*